package org.example.design.strategy.guess;

import java.util.Random;

/**
 * @author huangshen
 * @version 0
 * @description 策略实现类
 * @since 2022/2/8 9:00
 */
public class WinningStrategy implements Strategy {

    private final Random random;

    private boolean won = false;

    private Hand prevHand;

    public WinningStrategy(int seed) {
        this.random = new Random(seed);
    }

    @Override
    public Hand nextHand() {
        // 如果失败换一个手势，成功则保持上一个手势
        if(!won) {
           prevHand = Hand.getHand(random.nextInt(3));
        }
        return prevHand;
    }

    @Override
    public void study(boolean win) {
        this.won = win;
    }
}
